<template>
	<view class="content">
		<view class="row t_center head_img">
			<view class="col-24">
				<image src="../../static/public/logo.png" mode="heightFix"></image>
			</view>
			<view class="col-24 l_name">
				六时出行
			</view>
		</view>
		<view class="row head_message">
			<view class="col-24 apply t_size_32">
				申请获取以下权限
			</view>
			<view class="col-24 phone">
				获得您的绑定手机号(用于识别登录的唯一凭证)
			</view>
		</view>
		<view class="row">
			<view class="col-24">
				<button type="primary" class="t_size_32" @getphonenumber="getPhoneNumber" open-type="getPhoneNumber">微信一键登录</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				cont: {
					id: 0,
					telephone: '',
					sessionKey: ''
				}
			}
		},
		onLoad(option) {
			this.cont = JSON.parse(uni.getStorageSync('login_result'));
		},
		methods:{
			async getPhoneNumber(e){
				uni.showLoading()
				// #ifdef MP-WEIXIN
				if(e.detail.errMsg == "getPhoneNumber:ok"){
					let res = await this.$api.request(this.$api.user.bindTelephone,{
						"encryptedData": e.detail.encryptedData,
						"iv": e.detail.iv,
						"sessionKey": this.cont.sessionKey,
						"userId": this.cont.id
					})
					if(res){
						this.$public.showToast('绑定成功');
						setTimeout(()=>{
							uni.setStorage({
								key:'token',
								data:res.accessToken,
								success() {
									uni.removeStorageSync('login_result');
									uni.navigateBack()
								}
							})
						},1000)
						uni.hideLoading()
					}
				}
				// #endif
			}
		}
	}
</script>

<style lang="scss">
	.content{
		width: 88%;
		padding: 5rpx 6%;
		.head_img{
			margin-top: 45rpx;
			padding-bottom: 45rpx;
			border-bottom: 1px solid #EDEDED;
			image{
				height: 150rpx;
			}
			.l_name{
				height: 60rpx;
				line-height: 60rpx;
			}
		}
		.head_message{
			padding: 15rpx 0;
			.apply{
				height: 80rpx;
				line-height: 80rpx;
			}
			.phone{
				height: 40rpx;
				line-height: 40rpx;
				color: #B1AFAF;
			}
		}
		button[type="primary"]{
			height: 96rpx;
			line-height: 96rpx;
			border-radius: 48rpx;
			background-color: #6CBF30;
			margin-top: 116rpx;
		}
	}
</style>
